<!-- 通信类 决算  竣工决算信息 -->
<template>
  <TCollapse title="竣工决算信息">
    <div ref="queryFormBox" class="search-flex-box">
      <BtnConfig ref="btnConfigRef" class="marginBottom14" :btn-configs="basicList.manageMode !== '03' ? getbtnOptionOne : btnOptionTwo " @propClick="btnClick" />
      <Form ref="formRef" v-model="beCompletedMessageList" :form-option="formOption" :select-list="dicLists" />
    </div>
  </TCollapse>
</template>

<script>
import Form from '@/views/actualBudget/communication/tFbusiness/pmsForm'
import TCollapse from '@/components/basic/TCollapse.vue'
import BtnConfig from '@/components/basic/btnConfig.vue'
import {
    getSelectJGJSBConfigNew,
    getUserInfoNew,
    applyTokenByCodeNew,
    getIsPushNew,
    confirmationOfArrivalNew
} from '@/api/actualBudget/tFbusiness/index' // 列表接口
import { newOpenPostWindow } from '@/utils/newRequestCommonFormjs'
import { getTransferCapitalInfo } from '@/api/actualBudget/tFbusiness/index'
import { numberToQianFenWei } from '@/utils/numberToQianFenWei'
import { msgInfoEl } from '@/utils'

// 查询条件配置
const formOption = {
    size: 'mini',
    inline: true,
    labelWidth: '160px',
    itemData: [
        {
            type: 'input',
            prop: 'zanguMoney',
            value: '',
            width: '',
            colSpan: 6,
            clearable: true,
            disabled: true,
            label: '暂估金额'
        },
        {
            type: 'input',
            prop: 'zanguTime',
            value: '',
            width: '',
            colSpan: 6,
            clearable: true,
            disabled: true,
            label: '暂估时间'
        },
        {
            type: 'input',
            prop: 'forTotalMoney',
            value: '',
            width: '',
            colSpan: 6,
            clearable: true,
            disabled: true,
            label: '正式竣工决算总金额（元）'
        },
        {
            type: 'input',
            prop: 'forMoneyTime',
            value: '',
            width: '',
            colSpan: 6,
            clearable: true,
            disabled: true,
            label: '正式竣工决算时间'
        }
    ]
}
// 列表按钮配置
const btnOptionOne = [
    // { label: '采购订单清单表导出', fun: 'exportData', type: '' },
    { label: '获取财务转资信息', fun: 'getFinancialTransferInfo', type: '' },
    { label: '资产装配', fun: 'AssetAssembly', type: '' },
    { label: '查看竣工决算表', fun: 'selectJGJSB', type: '' },
    { label: '成本单信息', fun: 'costSheet', type: '' }
]

const btnOptionTwo = [
    { label: '获取财务转资信息', fun: 'getFinancialTransferInfo', type: '' }
]
export default {
    name: 'ActualTime',
    components: {
        BtnConfig,
        Form,
        TCollapse
    },
    props: {
        beCompletedMessageList: {
            type: Object,
            default: () => ({})
        },
        urlList: {
            type: Object,
            default: () => ({})
        },
        lcList: {
            type: Object,
            default: () => ({})
        },
        basicList: {
            type: Object,
            default: () => ({})
        }
    },
    computed: {
        getbtnOptionOne(){
            if (this.basicList.manageMode === '05' && +this.basicList.isNewbusiness === 1) {
                return this.btnOptionOne.filter(item => item.fun === 'getFinancialTransferInfo')
            } else if (this.basicList.manageMode === '51' && +this.basicList.isNewbusiness === 1) {
                return this.btnOptionOne.filter(item => item.fun !== 'AssetAssembly')
            } else {
                return this.btnOptionOne
            }
        }
    },
    data() {
        return {
            btnOptionOne,
            btnOptionTwo,
            formOption, // 查询条件配置项
            dialogCheckbox: false, // 自定义列表弹框
            dicLists: {} // 下拉框字典选项集合
        }
    },
    created() {
        console.log(this.basicList)
    },
    methods: {
        // 列表按钮点击事件
        btnClick(fun, row) {
            this[fun](row)
        },
        async getFinancialTransferInfo() {
            const _ids = this.basicList?.prjId||this.urlList?.prjId
            getTransferCapitalInfo(_ids).then((res) => {
                if (+res.code === 200) {
                    this.beCompletedMessageList.zanguMoney = res.data?.zanguMoney
                    this.beCompletedMessageList.zanguTime = res.data?.zanguTime
                    this.beCompletedMessageList.forTotalMoney = res.data?.forTotalMoney
                    this.beCompletedMessageList.forMoneyTime = res.data?.forMoneyTime
                    if (res.message) {
                        this.$message({
                            // 将html化
                            dangerouslyUseHTMLString: true,
                            message: res.message,
                            type: 'error'
                        })
                    } else {
                        msgInfoEl({
                            type: 'success',
                            message: '获取成功'
                        })
                    }
                }
            })
        },
        // 成本单信息
        async costSheet() {
            const today = new Date()
            const year = today.getFullYear()
            const month = today.getMonth() + 1 // 注意，getMonth()方法返回月份是从0开始的，所以需要加1
            const day = today.getDate()
            const endTime = year + '-' + month + '-' + day

            var getUserInfoList = {}
            var applyTokenByCodeList = {}
            var getSelectJGJSBConfigList = {}

            // 决算: 查询竣工决算表配置信息接口
            const getSelectJGJSBConfig = await getSelectJGJSBConfigNew({ itfCodeStatus: '1' })
            if (getSelectJGJSBConfig.code === '200') {
                getSelectJGJSBConfigList = getSelectJGJSBConfig.data
            }
            // 决算: 获取用户信息接口
            const getUserInfo = await getUserInfoNew({ })
            if (getUserInfo.code === '200') {
                getUserInfoList = getUserInfo.data
            }
            // 决算:
            const applyTokenByCode = await applyTokenByCodeNew({ serviceId: 'CHNTFMS', loginAcct: getUserInfoList.user.loginName })
            if (applyTokenByCode.code === '200') {
                applyTokenByCodeList = applyTokenByCode.data
                // 2022-04-28 跳转页面使用post方式
                var pwdaToken = applyTokenByCodeList.TOKEN
                var acctId = applyTokenByCodeList.ACCTID
                var toUrl = getSelectJGJSBConfigList.servUrl
                var params = {}
                params.pwdaToken = pwdaToken
                params.acctId = acctId
                params.Login = 'PMS_COST'
                params.flag = '1'
                params.ENDTIME = endTime
                params.STARTTIME = '2015-01-01'
                params.XMBH = this.basicList.prjCode
                params.DWBH = this.basicList.orgCode
                newOpenPostWindow(toUrl, params)
            }
        },
        // 资产装配
        async AssetAssembly() {
            // 综合查询进来获取不到PrJId
            const _ids = this.lcList?.bizObject?.prjId ? this.lcList.bizObject.prjId : this.urlList.prjId
            var arrivalState = false
            var prjId = _ids
            var isPush = ''
            var getUserInfoList = {}
            var applyTokenByCodeList = {}
            var getSelectJGJSBConfigList = {}

            const getIsPush = await getIsPushNew({ prjId: prjId })
            if (getIsPush.code === '200') {
                isPush = getIsPush.data
            }
            if (isPush === '1') {
                const confirmationOfArrival = await confirmationOfArrivalNew({ prjId: prjId, queryType: '6' })
                if (confirmationOfArrival.code === '200') {
                    arrivalState = true
                }
                if (confirmationOfArrival.code === '1019') {
                    // const { returnMsg } = JSON.parse(confirmationOfArrival?.data)
                    msgInfoEl({
                    message: confirmationOfArrival.message  || '操作异常',
                    type: 'error'
                })
                }
            } else {
                this.$message({
                    message: '物资未推送商合！',
                    type: 'warning'
                })
            }

            if (arrivalState === false) {
                return
            }

            // 决算: 查询竣工决算表配置信息接口
            const getSelectJGJSBConfig = await getSelectJGJSBConfigNew({ itfCodeStatus: '1' })
            if (getSelectJGJSBConfig.code === '200') {
                getSelectJGJSBConfigList = getSelectJGJSBConfig.data
            }
            // 决算: 获取用户信息接口
            const getUserInfo = await getUserInfoNew({ })
            if (getUserInfo.code === '200') {
                getUserInfoList = getUserInfo.data
            }
            // 决算: 获取财务token(登录信息)接口
            const applyTokenByCode = await applyTokenByCodeNew({ serviceId: 'CHNTFMS', loginAcct: getUserInfoList.user.loginName })
            if (applyTokenByCode.code === '200') {
                applyTokenByCodeList = applyTokenByCode.data
                // 2022-04-28 跳转页面使用post方式
                var pwdaToken = applyTokenByCodeList.TOKEN
                var acctId = applyTokenByCodeList.ACCTID
                var toUrl = getSelectJGJSBConfigList.servUrl
                var params = {}
                params.pwdaToken = pwdaToken
                params.acctId = acctId
                params.Login = 'PMS_ZP'
                params.flag = '1'
                console.log(toUrl, params, 'toUrlparams')
                newOpenPostWindow(toUrl, params)
            }
        },
        // 查看 决算竣工表
        async selectJGJSB() {
            var getSelectJGJSBConfigList = {}
            var getUserInfoList = {}
            var applyTokenByCodeList = {}

            // 决算: 查询竣工决算表配置信息接口
            const getSelectJGJSBConfig = await getSelectJGJSBConfigNew({ itfCodeStatus: '0' })
            if (getSelectJGJSBConfig.code === '200') {
                getSelectJGJSBConfigList = getSelectJGJSBConfig.data
            }

            // 决算: 获取用户信息接口
            const getUserInfo = await getUserInfoNew({})
            if (getUserInfo.code === '200') {
                getUserInfoList = getUserInfo.data
            }

            // 决算: 获取财务token(登录信息)接口
            const applyTokenByCode = await applyTokenByCodeNew({ serviceId: 'CHNTFMS', loginAcct: getUserInfoList.user.loginName })
            if (applyTokenByCode.code === '200') {
                applyTokenByCodeList = applyTokenByCode.data
                // 2022-04-28 跳转页面使用post方式
                var pwdaToken = applyTokenByCodeList.TOKEN
                var acctId = applyTokenByCodeList.ACCTID
                var toUrl = getSelectJGJSBConfigList.servUrl
                var params = {}
                params.pwdaToken = pwdaToken
                params.acctId = acctId
                params.Login = 'PMS_COST'
                params.AuthType = 'UserCode'
                params.AppCode = '0001'
                params.UserCode = getUserInfoList.user.loginName
                params.callType = '1'
                params.flag = '1'
                params.callPara = '/cwbase/web/session/gsprtf/adpdebug.aspx?ADPUrl=/cwbase/web/gspadp/debug/45b71827-ba5b-42db-9df2-b2acd53e620c/Index.html'
                console.log(toUrl, params, 'toUrlparams')
                newOpenPostWindow(toUrl, params)
            }
        }
    }
}
</script>

<style lang="scss" scoped>
.search-flex-box {
    // display: flex;
    // justify-content: space-between;
    height: auto;
}

.searchBtn {
    width: 100px;
    margin-left: auto;
    display: flex;
    margin-top: 4px;
    flex-direction: column;

    .el-button+.el-button {
        margin-left: 0;
        margin-top: 8px;
    }
}

.electronicSignature {
    width: 100%;

    .mainDetails {
        padding: 20px 25px 0px;
    }

    .topRemark {
        // background-color: #fdf5e6;
        background-color: #ffefd5;
        width: 100%;
        height: 40px;
        line-height: 40px;
        padding-left: 10px;
        font-size: 14px;

        .asterisk {
            color: #f00;
            margin-right: 2px;
            font-size: 18px;
        }
    }

    .customBtn {
        height: 20px;
        line-height: 20px;
        font-size: 14px;
        margin: 10px 20px 10px 90%;
        cursor: pointer;

        .el-icon-s-tools {
            font-size: 20px;
            color: #999;
            margin-right: 6px;
        }
    }
}

.el-button--text {
    color: #02a7f0;
}

.el-button--primary {
    color: #fff;
}

.dialog-footer {
    display: flex;
    justify-content: center;
}

::v-deep .el-button+.el-button {
    color: #fff;
}

// 弹框样式
::v-deep .el-dialog__body {
    max-height: 400px;
    overflow-y: auto;
    margin: 0px;
}

// 滚动条样式
::v-deep .el-dialog__body::-webkit-scrollbar {
    // 滚动条整体样式
    width: 6px; //高宽分别对应横竖滚动条的尺寸
    height: 10px;
}

::v-deep .el-dialog__body::-webkit-scrollbar-thumb {
    // 滚动条里面小方块
    border-radius: 10px;
    // -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    background: #f2f3f5;
}

::v-deep .el-range-editor.el-input__inner {
    padding: 0px 10px;
}

.topBtn {
    text-align: center;
    padding: 20px;
}

::v-deep .el-tag {
    border: none;
    color: #02a7f0;
    background-color: #ffffff;
}

::v-deep .el-dialog__title {
    font-size: 14px;
    font-weight: bold;
}

::v-deep .el-col-24 {
    height: 110px;
}

::v-deep .el-textarea.is-disabled .el-textarea__inner {
    background-color: #f7f7f7;
}
</style>
